package com.chat.datea.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.HotSingerEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 周橹 on 15/10/21.
 */
public class SingerViewPagerAdapter extends PagerAdapter {

    private View view;
    private Context mContext;
    private List<HotSingerEntity.ArtistEntity> mArtistEntities;
    private ImageView singer_img_left, singer_img_middle, singer_img_right;
    private TextView singer_name_left, singer_name_middle, singer_name_right;

    public SingerViewPagerAdapter(Context context, List<HotSingerEntity.ArtistEntity> artistEntities) {
        this.mContext = context;
        this.mArtistEntities = artistEntities;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        view = LayoutInflater.from(mContext).inflate(R.layout.singer_viewpager_item, null);

        singer_name_left = (TextView) view.findViewById(R.id.singer_name_left);
        singer_name_middle = (TextView) view.findViewById(R.id.singer_name_medium);
        singer_name_right = (TextView) view.findViewById(R.id.singer_name_right);

        singer_img_left = (ImageView) view.findViewById(R.id.singer_img_left);
        singer_img_middle = (ImageView) view.findViewById(R.id.singer_img_medium);
        singer_img_right = (ImageView) view.findViewById(R.id.singer_img_right);
        Log.i("chouru", mArtistEntities.get(position).toString() + "");
        if (position == 0) {
            String left = mArtistEntities.get(0).getAvatar_big();
            String middle = mArtistEntities.get(1).getAvatar_big();
            String right = mArtistEntities.get(2).getAvatar_big();
            Picasso.with(mContext).load(left).placeholder(R.mipmap.default_recommend).into(singer_img_left);
            Picasso.with(mContext).load(middle).placeholder(R.mipmap.default_recommend).into(singer_img_middle);
            Picasso.with(mContext).load(right).placeholder(R.mipmap.default_recommend).into(singer_img_right);
            singer_name_left.setText(mArtistEntities.get(0).getName());
            singer_name_middle.setText(mArtistEntities.get(1).getName());
            singer_name_right.setText(mArtistEntities.get(2).getName());
        } else if (position == 1) {
            String left = mArtistEntities.get(3).getAvatar_big();
            String middle = mArtistEntities.get(4).getAvatar_big();
            String right = mArtistEntities.get(5).getAvatar_big();
            Picasso.with(mContext).load(left).placeholder(R.mipmap.default_recommend).into(singer_img_left);
            Picasso.with(mContext).load(middle).placeholder(R.mipmap.default_recommend).into(singer_img_middle);
            Picasso.with(mContext).load(right).placeholder(R.mipmap.default_recommend).into(singer_img_right);

            singer_name_left.setText(mArtistEntities.get(3).getName());
            singer_name_middle.setText(mArtistEntities.get(4).getName());
            singer_name_right.setText(mArtistEntities.get(5).getName());
        } else if (position == 2) {
            String left = mArtistEntities.get(6).getAvatar_big();
            String middle = mArtistEntities.get(7).getAvatar_big();
            String right = mArtistEntities.get(8).getAvatar_big();
            Picasso.with(mContext).load(left).placeholder(R.mipmap.default_recommend).into(singer_img_left);
            Picasso.with(mContext).load(middle).placeholder(R.mipmap.default_recommend).into(singer_img_middle);
            Picasso.with(mContext).load(right).placeholder(R.mipmap.default_recommend).into(singer_img_right);

            singer_name_left.setText(mArtistEntities.get(6).getName());
            singer_name_middle.setText(mArtistEntities.get(7).getName());
            singer_name_right.setText(mArtistEntities.get(8).getName());
        } else if (position == 3) {
            String left = mArtistEntities.get(9).getAvatar_big();
            String middle = mArtistEntities.get(10).getAvatar_big();
            String right = mArtistEntities.get(11).getAvatar_big();
            Picasso.with(mContext).load(left).placeholder(R.mipmap.default_recommend).into(singer_img_left);
            Picasso.with(mContext).load(middle).placeholder(R.mipmap.default_recommend).into(singer_img_middle);
            Picasso.with(mContext).load(right).placeholder(R.mipmap.default_recommend).into(singer_img_right);
            singer_name_left.setText(mArtistEntities.get(9).getName());
            singer_name_middle.setText(mArtistEntities.get(10).getName());
            singer_name_right.setText(mArtistEntities.get(11).getName());
        }

        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
